package com.ruoyi.standingbook.extermination.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.standingbook.extermination.domain.vo.ExterminationImportDetailVo;
import com.ruoyi.standingbook.extermination.service.IExterminationService;
import com.ruoyi.standingbook.extermination.service.impl.ExterminationExcelService;
import com.ruoyi.standingbook.recycle.domain.bo.RecycleImportBaseBo;
import com.ruoyi.standingbook.recycle.domain.vo.RecycleImportDetailVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.extermination.domain.vo.ExterminationImportBaseVo;
import com.ruoyi.standingbook.extermination.domain.bo.ExterminationImportBaseBo;
import com.ruoyi.standingbook.extermination.service.IExterminationImportBaseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 四害消杀导入
 *
 * @author cc
 * @date 2023-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/exterminationImportBase")
public class ExterminationImportBaseController extends BaseController {

    private final IExterminationImportBaseService iExterminationImportBaseService;

    private final ExterminationExcelService exterminationExcelService;


    /**
     * 查询四害消杀导入列表
     */
    @SaCheckPermission("standingbook:exterminationImportBase:list")
    @GetMapping("/list")
    public TableDataInfo<ExterminationImportBaseVo> list(ExterminationImportBaseBo bo, PageQuery pageQuery) {
        return iExterminationImportBaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出四害消杀导入列表
     */
    @SaCheckPermission("standingbook:exterminationImportBase:export")
    @Log(title = "四害消杀导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExterminationImportBaseBo bo, HttpServletResponse response) {
        List<ExterminationImportBaseVo> list = iExterminationImportBaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "四害消杀导入", ExterminationImportBaseVo.class, response);
    }

    /**
     * 获取四害消杀导入详细信息
     *
     * @param batchNo 主键
     */
    @SaCheckPermission("standingbook:exterminationImportBase:query")
    @GetMapping("/{batchNo}")
    public R<ExterminationImportBaseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String batchNo) {
        return R.ok(iExterminationImportBaseService.queryById(batchNo));
    }

    /**
     * 新增四害消杀导入
     */
    @SaCheckPermission("standingbook:exterminationImportBase:add")
    @Log(title = "四害消杀导入", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExterminationImportBaseBo bo) {
        return toAjax(iExterminationImportBaseService.insertByBo(bo));
    }

    /**
     * 修改四害消杀导入
     */
    @SaCheckPermission("standingbook:exterminationImportBase:edit")
    @Log(title = "四害消杀导入", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExterminationImportBaseBo bo) {
        return toAjax(iExterminationImportBaseService.updateByBo(bo));
    }

    /**
     * 删除四害消杀导入
     *
     * @param batchNos 主键串
     */
    @SaCheckPermission("standingbook:exterminationImportBase:remove")
    @Log(title = "四害消杀导入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{batchNos}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] batchNos) {
        return toAjax(iExterminationImportBaseService.deleteWithValidByIds(Arrays.asList(batchNos), true));
    }

    /**
     * 新增导入主
     */
    @SaCheckPermission("standingbook:exterminationImportBase:add")
    @Log(title = "四害消杀导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping("/importData")
    public R<Void> importData(@Validated(AddGroup.class) @RequestBody ExterminationImportBaseBo bo) {
        return toAjax(this.exterminationExcelService.importExcel(bo));
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "四害消杀数据", ExterminationImportDetailVo.class, response);
    }
}
